package com.yk.mr.controller.manage;

import com.jcraft.jsch.JSchException;
import com.yk.mr.service.manage.api.IJobManageService;
import org.json.JSONException;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.Map;

@Controller
@RequestMapping("/manage")
public class ManageController {
    @Resource(name = "jobManageService")
    private IJobManageService jobManageService;

    //    @RequestMapping("startJob")
//    @ResponseBody
//    public Object startJob(@RequestParam String jobId,@RequestParam String input,@RequestParam String output) throws JSONException {
//        return this.jobManageService.startJob(jobId,new JSONArray(input),output);
//    }


    @RequestMapping("startJob")
    @ResponseBody
    public Map<String,Object> startJob(@RequestParam String jobId, @RequestParam(defaultValue = "633acfed-d72b-4d12-952a-e3f345c31183") String clusterId) throws JSONException, JSchException {
        return this.jobManageService.startJob(jobId,clusterId);
    }

    @RequestMapping("stopJob")
    @ResponseBody
    public Object stopJob(@RequestParam String jobId) throws Exception {

        return this.jobManageService.stopJob(jobId);
    }

    @RequestMapping("getJobStatus")
    @ResponseBody
    public Object getJobSubmitStatus(@RequestParam String jobId) throws Exception {
        return this.jobManageService.queryProcessState(jobId);
    }
}
